﻿using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using BLL;
using Model;

public partial class ViewbyProduct_LatestCategory : System.Web.UI.Page
{
    private int count;

    protected void Page_Load(object sender, EventArgs e)
    {
        BindWeekData();
    }

    private void BindWeekData()
    {
        Test test = new Test();
        IList<TestInfo> list = test.GetTestsbyWeek_DT();
        count = list.Count;
        GridView1.DataSource = list;
        GridView1.DataBind();
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            if (GridView1.Rows[i].Cells[7].Text == "Fail")
                GridView1.Rows[i].Cells[7].ForeColor = System.Drawing.Color.Red;
        }
    }
    
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Session["productSN"] = GridView1.SelectedDataKey["ProductSN"].ToString();
        Session["testTime"] = Convert.ToDateTime(GridView1.SelectedDataKey["TestTime"]);
        Session["ProductTypeID"] = GridView1.SelectedDataKey["ProductTypeID"].ToString();
        Session["UserID"] = GridView1.SelectedDataKey["UserID"].ToString();
        Session["ENAID"] = GridView1.SelectedDataKey["ENAID"].ToString();
        Session["SpecVersion"] = GridView1.SelectedDataKey["SpecVersion"].ToString();
        Session["IsPass"] = GridView1.SelectedDataKey["IsPass"].ToString();

        Response.Redirect("~/ViewTest/ViewYourself/ViewTestItem.aspx");
    }
    
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.GridView1.PageIndex = e.NewPageIndex;
        BindWeekData();
    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            Label lbl = (Label)e.Row.FindControl("Label2");
            lbl.Text = count.ToString();
        }
    }
}
